//
//  CustomBtn.m
//  ProfilePicture
//
//  Created by 张云江 on 2019/10/16.
//  Copyright © 2019年 张云江. All rights reserved.
//

#import "CustomBtn.h"

@implementation CustomBtn

- (instancetype)init
{
    self = [super init];
    if (self) {
        
    }
    return self;
}

- (void)setCustomBtnwtihNormal:(NSString *)imagePath withSelected:(NSString *)imageSePath withLabel:(NSString *)des
{
    aabtn = [[UIButton alloc] init];
    aabtn.userInteractionEnabled = NO;
    [aabtn setImage:[UIImage imageNamed:imagePath] forState:UIControlStateNormal];
    [aabtn setImage:[UIImage imageNamed:imageSePath] forState:UIControlStateSelected];
    [aabtn setTitleColor:kUIColorFromRGA(0x000000, 0.25) forState:UIControlStateNormal];
    [self addSubview:aabtn];
    [aabtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.top.equalTo(self.mas_top).offset(kRatio(12));
        make.width.height.mas_equalTo(kRatio(22));
    }];
    
    aalabel = [[UILabel alloc]init];
    aalabel.text = des;
    aalabel.font = [UIFont systemFontOfSize:kRatio(10)];
    aalabel.textColor = kUIColorFromRGA(0x000000, 0.25);
    [self addSubview:aalabel];
    [aalabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.bottom.equalTo(self.mas_bottom).offset(kRatio(-8));
        make.height.mas_equalTo(kRatio(12));
    }];
}

- (void)setCustom2BtnwtihNormal:(NSString *)imagePath withSelected:(NSString *)imageSePath withLabel:(NSString *)des
{
    aabtn = [[UIButton alloc] init];
    aabtn.userInteractionEnabled = NO;
    [aabtn setImage:[UIImage imageNamed:imagePath] forState:UIControlStateNormal];
    [aabtn setImage:[UIImage imageNamed:imageSePath] forState:UIControlStateSelected];
    [aabtn setTitleColor:kUIColorFromRGA(0x000000, 0.25) forState:UIControlStateNormal];
    [self addSubview:aabtn];
    [aabtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.top.equalTo(self.mas_top).offset(kRatio(5));
        make.width.height.mas_equalTo(kRatio(36));
    }];
    
    aalabel = [[UILabel alloc]init];
    aalabel.text = des;
    aalabel.font = [UIFont systemFontOfSize:kRatio(12)];
    aalabel.textColor = kUIColorFromRGA(0x000000, 0.25);
    [self addSubview:aalabel];
    [aalabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.bottom.equalTo(self.mas_bottom).offset(kRatio(-6));
        make.height.mas_equalTo(kRatio(14));
    }];
}

- (void)setCustom3withLabel:(NSString *)des
{
    aalabel = [[UILabel alloc]init];
    aalabel.text = des;
    aalabel.font = [UIFont systemFontOfSize:kRatio(12)];
    aalabel.textColor = kUIColorFromRGA(0x000000, 0.25);
    [self addSubview:aalabel];
    [aalabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.top.equalTo(self.mas_top).offset(kRatio(6));
        make.height.mas_equalTo(kRatio(14));
    }];
    
    line = [[UIView alloc]init];
    line.hidden = YES;
    line.backgroundColor = kUIColorFromRGB(0x2F54EB);
    line.layer.cornerRadius = 1.5;
    line.layer.masksToBounds = YES;
    
    [self addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.bottom.equalTo(self.mas_bottom).offset(kRatio(-10));
        make.width.mas_equalTo(kRatio(14));
        make.height.mas_equalTo(kRatio(3));
    }];
}

- (void)setCustom6withLabel:(NSString *)des
{
    aalabel = [[UILabel alloc]init];
    aalabel.text = des;
    aalabel.font = [UIFont systemFontOfSize:kRatio(16)];
    aalabel.textColor = kUIColorFromRGA(0x000000, 0.25);
    [self addSubview:aalabel];
    [aalabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.top.equalTo(self.mas_top).offset(kRatio(6));
        make.height.mas_equalTo(kRatio(14));
    }];
    
    line = [[UIView alloc]init];
    line.hidden = YES;
    line.backgroundColor = kUIColorFromRGB(0x2F54EB);
    line.layer.cornerRadius = 1.5;
    line.layer.masksToBounds = YES;
    
    [self addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.bottom.equalTo(self.mas_bottom).offset(kRatio(-10));
        make.width.mas_equalTo(kRatio(14));
        make.height.mas_equalTo(kRatio(3));
    }];
}

- (void)setCustom4BtnwtihNormal:(NSString *)imagePath withLabel:(NSString *)des
{
    self.layer.borderColor = kUIColorFromRGA(0x000000, 0.25).CGColor;
    self.layer.cornerRadius = 5;
    self.layer.masksToBounds = YES;
    self.layer.borderWidth = 2;
    
    UIImageView *icon = [[UIImageView alloc]init];
    NSURL *url = [NSURL URLWithString:imagePath];
    [icon sd_setImageWithURL:url];
    [self addSubview:icon];
    [icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(self).offset(kRatio(2));
        make.right.equalTo(self).offset(kRatio(-2));
    }];
    
    aalabel = [[UILabel alloc]init];
    aalabel.text = des;
    aalabel.textAlignment = NSTextAlignmentCenter;
    aalabel.backgroundColor = [UIColor whiteColor];
    aalabel.font = [UIFont systemFontOfSize:kRatio(12)];
    aalabel.textColor = kUIColorFromRGA(0x000000, 0.25);
    [self addSubview:aalabel];
    [aalabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(self.mas_width).offset(kRatio(-4));
        make.centerX.equalTo(self.mas_centerX);
        make.bottom.equalTo(self.mas_bottom).offset(kRatio(-2));
        make.height.mas_equalTo(kRatio(20));
    }];
}

- (void)setCustom5BtnwtihNormal:(NSString *)des withLabel:(NSString *)des1
{
    self.backgroundColor = kUIColorFromRGB(0xF3F5FF);
    self.layer.cornerRadius = 8;
    self.layer.masksToBounds = YES;
    
    UILabel *number = [[UILabel alloc]init];
    number.text = des;
    number.textAlignment = NSTextAlignmentCenter;
    number.textColor = kUIColorFromRGB(0xFE7A38);
    number.font = [UIFont systemFontOfSize:kRatio(18) weight:75];
    [self addSubview:number];
    [number mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(self.mas_width).offset(kRatio(-4));
        make.centerX.equalTo(self.mas_centerX);
        make.top.equalTo(self.mas_top).offset(kRatio(10));
        
        make.height.mas_equalTo(kRatio(20));
    }];
    
    UILabel *deslabe = [[UILabel alloc]init];
    deslabe.text = des1;
    deslabe.font = [UIFont systemFontOfSize:kRatio(12)];
    deslabe.textAlignment = NSTextAlignmentCenter;
    deslabe.textColor = kUIColorFromRGA(0x000000, 0.4);
    [self addSubview:deslabe];
    [deslabe mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.bottom.equalTo(self.mas_bottom).offset(kRatio(-8));
        make.height.mas_equalTo(kRatio(14));
    }];
}

- (void)setCustomSelected:(BOOL)selected
{
    if (selected == YES) {
        aabtn.selected = YES;
        line.hidden = NO;
        aalabel.textColor = kUIColorFromRGA(0x2F54EB, 1);
    } else {
        aabtn.selected = NO;
        line.hidden = YES;
        aalabel.textColor = kUIColorFromRGA(0x000000, 0.25);
    }
    self.selected = selected;
}

- (void)setCustomStyeSelected:(BOOL)selected
{
    if (selected == YES) {
        if (self.tag != 100) {
            aalabel.backgroundColor = kUIColorFromRGB(0x2F54EB);
            aalabel.textColor = [UIColor whiteColor];
            self.layer.borderColor = kUIColorFromRGB(0x2F54EB).CGColor;
        }
    } else {
        if (self.tag != 100) {
            self.layer.borderColor = kUIColorFromRGA(0x000000, 0.25).CGColor;
            aalabel.backgroundColor = [UIColor whiteColor];
            aalabel.textColor = kUIColorFromRGA(0x000000, 0.25);
        }
    }
    self.selected = selected;
}

- (void)setCustom6Selected:(BOOL)selected
{
    if (selected == YES) {
        aabtn.selected = YES;
        line.hidden = NO;
        aalabel.font = [UIFont systemFontOfSize:kRatio(16) weight:200];
        aalabel.textColor = kUIColorFromRGA(0x2F54EB, 1);
    } else {
        aabtn.selected = NO;
        line.hidden = YES;
        aalabel.font = [UIFont systemFontOfSize:kRatio(16)];
        aalabel.textColor = kUIColorFromRGA(0x000000, 0.25);
    }
    self.selected = selected;
}
@end
